package cn.com.clearbus.mini.service.impl;

import cn.com.clearbus.event.UpLoadFileEvent;
import cn.com.clearbus.mini.entity.MiniFile;
import cn.com.clearbus.mini.entity.MiniUser;
import cn.com.clearbus.mini.mapper.FileMapper;
import cn.com.clearbus.mini.mapper.MiniUserMapper;
import cn.com.clearbus.mini.service.IFileService;
import cn.com.clearbus.mini.service.IMiniUserService;
import cn.com.clearbus.result.DynamicResult;
import cn.com.clearbus.result.ErrCode;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.stereotype.Service;
import org.springframework.web.context.WebApplicationContext;



@Service
public class FileServiceImpl extends ServiceImpl<FileMapper, MiniFile> implements IFileService {

    @Autowired
    WebApplicationContext wac;

    @Autowired
    FileMapper fileMapper;

    @Override
    public DynamicResult uploadFileInfo(MiniFile miniFile) {
        if (fileMapper.insert(miniFile) == 0 ? false:true) {
            //補發一個通知事件
            wac.publishEvent(new UpLoadFileEvent(miniFile,"发送邮件"));
            return new DynamicResult(ErrCode.SUCCESS,"插入成功");
        }
        return new DynamicResult(ErrCode.SUCCESS,"插入失败");
    }
}
